﻿<div ng-controller="MyLockOrderListC">
    <div class="bg-light lter b-b wrapper-md">
        <h1 class="m-n font-thin h3">锁价单管理</h1>
    </div>
    <div class="bg-light lter b-b wrapper-md">
        <div class="row">
            <div class="col-xs-12 input-group" style="padding: 0px 15px 5px">
                <input type="text" class="form-control" id='findname' placeholder="按名称查找" ng-model="findname">
                    <span class="input-group-btn">
                        <button class="btn btn-default" type="button" ng-click="find('')">查找</button>
                    </span>
            </div>
        </div>
        <div class="row">
            <div class="col-xs-8 btn-group dropdown" dropdown>
                <button class="btn btn-default" dropdown-toggle>按锁价单状态查看 <span class="caret"></span></button>
                <ul class="dropdown-menu">
                        <li ng-click="find('')"><a href>查看全部</a></li>
                        <li ng-click="find(3)"><a href>审批中</a></li>
                        <li ng-click="find(4)"><a href>已暂停</a></li>
                        <li ng-click="find(6)"><a href>取消</a></li>
                        <li ng-click="find(7)"><a href>审核通过</a></li>
                        <li ng-click="find(9)"><a href>已退款</a></li>
                </ul>
            </div>
            <div class="col-xs-4 btn-group">
                <button class="btn btn-default" ng-click="add()">新建锁价单</button>
            </div>
        </div>
    </div>
    <a ng-click="detail($index)" ng-repeat="item in lockOrders">
        <div class="panel panel-default" style="margin-bottom: 10px">
            <div class="panel-heading">
                <h3 class="panel-title">{{item.Customer.ShortName}}</h3>
            </div>
            <div class="panel-body">
                <div class="row">
                    <div class="col-xs-6"><strong>仓库：</strong>{{item.Provider.Name}}</div>
                    <div class="col-xs-6">
                        <strong>状态：</strong>
                        <span ng-if="item.IsApproval">审批中</span>
                        <span ng-if="item.IsPause">已暂停</span>
                        <span ng-if="!item.IsPause&&!item.IsApproval">
                            <span ng-if="item.ProcessState == 0">正常</span>
                            <span ng-if="item.ProcessState == 1">议价</span>
                            <span ng-if="item.ProcessState == 2">锁价</span>
                            <span ng-if="item.ProcessState == 3">款项确认</span>
                            <span ng-if="item.ProcessState == 4">完结</span>/
                            <span ng-if="item.State == 0">待确认</span>
                            <span ng-if="item.State == 6">取消</span>
                            <span ng-if="item.State == 7">审核通过</span>
                            <span ng-if="item.State == 9">已退款</span>
                        </span>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-6"><strong>锁价单总额：</strong>{{item.Total | number:2}}</div>
                    <div class="col-xs-6">
                        <strong>是否标件：</strong>
                        <span ng-if="!item.IsStandard">非标件</span>
                        <span ng-if="item.IsStandard">标件</span>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-12"><strong>备注：</strong>{{item.Remarks}}</div>
                </div>
            </div>
            <div class="panel-footer">{{item.CreateTime}}</div>
        </div>
    </a>
</div>

<script>
    angular.module('app') //锁价单列表控制器
    .controller("MyLockOrderListC", function ($scope, $state, $http,toSave) {
        $scope.pageData = {};
        $scope.pageData.Page = 0;
        $scope.state = "";
        $scope.findname = "";
        $scope.pageData.Rows = $scope.defPageRows;
        $scope.getData = function (p, r) {
            if (p) {
                p = p < 1 ? 1 : p;
            } else p = 1;
            if (r) {
            } else r = $scope.defPageRows;
             toSave.save_pages_lis(p,r);//保存当前页码和条数
            // console.log(toSave.get_pages(),toSave.get_lis());
            $http({
                url: "../api/ClientManager/LockOrderList?page=" + p + "&rows=" + r + "&keyword=" + $scope.findname + "&state=" + $scope.state,
                method: "GET"
            })
            .then(function (res) {
                $scope.lockOrders = res.data.Data;
            })
            .then(function (error) {
                if (error) {
                    alert("数据获取失败");
                }
            });
        };
        $scope.add = function (index) {
            $state.go('app.LockOrder_Add');
        };
        $scope.detail = function (index) {
            $state.go('app.MyLockOrder_Detail', {
                orderid: JSON.stringify($scope.lockOrders[index].Id)
            });
        };
        $scope.find = function (state) {
            if(state || state == ''){
                $scope.state=state;
            }
            localStorage.setItem('c',$scope.state);
            // console.log(localStorage.getItem('c'));
            toSave.save_inputs();//点击查询先保存input里面的值
            $scope.getData(1, $scope.pageData.Rows);
        };

         if (toSave.get_inputs()|| localStorage.getItem('c') != null) {
                    $scope.findname=toSave.get_inputs('findname');//把保存该id名的值取出来赋值给input框
                    $scope.state=localStorage.getItem('c');
                    $scope.getData(1, $scope.pageData.Rows);
         }else{
                    $scope.getData(1, $scope.pageData.Rows);
         }
    });
</script>
<script src="js/services/toSave.js"></script>